#!/bin/bash

echo '开放端口'
firewall-cmd --zone=public --add-port=9092/tcp --permanent
firewall-cmd --zone=public --add-port=9093/tcp --permanent
firewall-cmd --zone=public --add-port=9998/tcp --permanent

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

echo '创建文件'
mkdir -p ./volume/kafka/{data,config} &&
  chown -R 1001:0 ./volume/kafka

# 主机ip
ip=$(ip addr | grep ens | awk -F ' ' 'NR==2{print $2}' | awk -F '/' '{print $1}')
echo "修改 kafka 配置文件 主机ip为: $ip"
sed -i "/^KAFKA_CFG_ADVERTISED_LISTENERS=/c KAFKA_CFG_ADVERTISED_LISTENERS=BROKER://kafka:9092,EXTERNAL://$ip:9093" ./env/kafka.env

echo '启动容器'
docker-compose up -d

echo '查看容器'
docker-compose ps

# docker-compose down && rm -rf volume
